﻿@using ZBJF.Warranty.BLL
@{
    ViewBag.Title = "查看分月详情";
}
<style type="text/css">
    body, html {
        background-color: white;
    }
</style>
<div class="bg-master height-40">
    <img src="/Images/forward-left.png" class="forward_img" onclick="history.back(-1)" />
    <input class="weui-input date-calendar w-p75 align-center" id="date" type="text">
</div>
<div class="weui-panel weui-panel_access">
    <div class="weui-panel__hd">
        收入 ￥<label id="saleIncome" class="margin-r-10"></label>
        销量 <label id="saleCount"></label> 份
    </div>
    <div class="weui-panel__bd">

    </div>
    <div class="weui-loadmore" style="display: none">
        <i class="weui-loading"></i>
        <span class="weui-loadmore__tips">上拉加载更多数据</span>
    </div>
    <div class="weui-nomore weui-loadmore_line weui-loadmore_dot" style="display: none">
        <span class="weui-loadmore__tips">没有更多数据了</span>
    </div>
</div>
<script>
    $(function () {
        var iDisplayLength = parseInt((document.documentElement.clientHeight) / 80);
        var currentPageIndex = 0;
        var loading = false;  //状态标记
        $("#date").val("");//防止回退的时候有值导致无法选择日历（乱码），不能有年月这样的初始值
        $("#date").calendar({
            multiple: false,
            dateFormat: 'yyyy年mm月',
            onChange: function (p, values, displayValues) {
                if (values == $("#date").val()) //values变了， $("#date").val()没变
                    return;
                //摧毁与重新初始化
                $(document.body).destroyInfinite();
                $('.weui-panel__bd').html("");
                var currentPageIndex = 0;
                var loading = false; //状态标记
                $(document.body).infinite(100).on("reinfinite", function () { //reinfinite这个名字是随便取的，与第一个不一样即可
                    if (loading) return;
                    loading = true;
                    $.ajax({
                        url: "/InsuranceProductOrderCard/GetInsuranceProductOrderCardByOneMonth",
                        data: {
                            iDisplayStart: currentPageIndex * iDisplayLength,
                            iDisplayLength: iDisplayLength,
                            InsuranceProductOrderId: "@Request["InsuranceProductOrderId"]",
                            Status: "@Request["Status"]",
                            MonthDateTime: function () {
                                return values; ////values变了， $("#date").val()没变，所以这里应该传values而不是 $("#date").val()
                            }
                        },
                        success: function (result) {
                            loading = false;
                            currentPageIndex++;
                            var html = "";
                            if (result && result.list && result.list.length > 0) {
                                for (var i = 0; i < result.list.length; i++) {
                                    var item = result.list[i];
                                    html += "<a href='/InsuranceProductOrder/Detail/" + item.InsuranceProductOrderID + "' class=\"weui-media-box weui-media-box_appmsg\"><div class=\"weui-media-box__bd\"><div>";
                                    html += "<label class=\"w-200\">" + item.InsuranceProductName + "</label>";
                                    html += "<p class=\"sale-qty\">" + item.StatusDesc + "</p></div><div class=\"margin-t-20\">";
                                    html += "<p class=\"weui-media-box__desc  date-clock w-120 float-left\">" + item.CreateTime + "</p></div></div></a>";
                                }
                            }
                            $("#saleIncome").text(result.saleIncome);
                            $("#saleCount").text(result.saleCount);
                            $('.weui-panel__bd').append(html);
                            if (result.isLastPage) {
                                $(document.body).destroyInfinite();
                                $('.weui-loadmore').hide();
                                $('.weui-nomore').show();
                            } else {
                                if (currentPageIndex >= 1)
                                    $('.weui-loadmore').show();
                            }
                        }
                    });
                });
                $(document.body).trigger("reinfinite");
            }
        }).val("@DateTime.Now.ToString("yyyy年MM月")");

        $(document.body).infinite(100).on("infinite", function () {
            if (loading) return;
            loading = true;
            $.ajax({
                url: "/InsuranceProductOrderCard/GetInsuranceProductOrderCardByOneMonth",
                data: {
                    iDisplayStart: currentPageIndex * iDisplayLength, iDisplayLength: iDisplayLength,
                    InsuranceProductOrderId: "@Request["InsuranceProductOrderId"]",
                    Status: "@Request["Status"]",
                    MonthDateTime: function () {
                        return $("#date").val();
                    }
                },
                success: function (result) {
                    loading = false;
                    currentPageIndex++;
                    var html = "";
                    if (result && result.list && result.list.length > 0) {
                        for (var i = 0; i < result.list.length; i++) {
                            var item = result.list[i];
                            html += "<a href='/InsuranceProductOrder/Detail/" + item.InsuranceProductOrderID + "' class=\"weui-media-box weui-media-box_appmsg\"><div class=\"weui-media-box__bd\"><div>";
                            html += "<label class=\"w-200\">" + item.InsuranceProductName + "</label>";
                            html += "<p class=\"sale-qty\">" + item.StatusDesc + "</p></div><div class=\"margin-t-20\">";
                            html += "<p class=\"weui-media-box__desc  date-clock w-120 float-left\">" + item.CreateTime + "</p></div></div></a>";
                        }
                    }
                    $("#saleIncome").text(result.saleIncome);
                    $("#saleCount").text(result.saleCount);
                    $('.weui-panel__bd').append(html);
                    if (result.isLastPage) {
                        $(document.body).destroyInfinite();
                        $('.weui-loadmore').hide();
                        $('.weui-nomore').show();
                    } else {
                        if (currentPageIndex >= 1)
                            $('.weui-loadmore').show();
                    }
                }
            });
        });
        $(document.body).trigger("infinite");
    })
</script>
